package com.ybwh.springboot2.vueadmin.sys.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Preconditions;
import com.ybwh.springboot2.vueadmin.sys.dao.SysAccountRoleMapper;
import com.ybwh.springboot2.vueadmin.sys.model.po.SysAccountRole;
import com.ybwh.springboot2.vueadmin.sys.service.SysAccountRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 账号角色关联表服务接口实现类
 * </p>
 *
 * @author Fan Beibei
 * @version V1.0
 * @since 2023-04-08 19:57:22
 */
@Slf4j
@Service
public class SysAccountRoleServiceImpl implements SysAccountRoleService {
    @Resource
    private SysAccountRoleMapper sysAccountRoleMapper;




    @Override
    public PageInfo<SysAccountRole> queryByPage(SysAccountRole param, int pageNum, int pageSize) {
        Preconditions.checkArgument(pageNum > 0);
        Preconditions.checkArgument(pageSize > 0);

        Page<SysAccountRole> page =  sysAccountRoleMapper.selectByPage(param,pageNum,pageSize);

        return new PageInfo<>(page);
    }






//------------以上是生成代码-----------------------------------------------------------------------------------------------------------------

    @Override
    public Set<Long> queryByUserId(Long userId) {

        List<SysAccountRole> arList = sysAccountRoleMapper.selectByAccountId(userId);
        if (!CollectionUtils.isEmpty(arList)) {
            return arList.stream().map(SysAccountRole::getRoleId).
                    collect(Collectors.toSet());
        }

        return null;
    }







}
